package com.burpee.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.burpee.dao.BoardItemsDao;
import com.burpee.ui.Boarditems;

@Service(value="BoardItemsService")
public class BoardItemsServiceImpl implements BoardItemsService {

	@Autowired
	BoardItemsDao boardItemsDao;

	public List<Boarditems> list(long boardListNo, String searchCondition, String searchTitle, long pageNo) {

		List<Boarditems> itemList = null;

		itemList = boardItemsDao.itemviewnotice(boardListNo);

		if( searchTitle == null || searchTitle.trim().length() == 0){
			itemList.addAll(boardItemsDao.itemviewnotnotice(boardListNo, pageNo));
		}
		else{

			if(searchCondition.equals("T")){
				itemList.addAll(boardItemsDao.itemviewnotnoticeByTitle(boardListNo, searchTitle, pageNo));
			}
			else if(searchCondition.equals("C")){
				itemList.addAll(boardItemsDao.itemviewnotnoticeByContent(boardListNo, searchTitle, pageNo));
			}
			else if(searchCondition.equals("N")){
				itemList.addAll(boardItemsDao.itemviewnotnoticeByMemberName(boardListNo, searchTitle, pageNo));
			}

		}

		return itemList;
	}
	
	public  List<Boarditems> list2(){
		
		return boardItemsDao.list();
		
	}

	public Boarditems view(long boardItemsNo) {

		return boardItemsDao.view(boardItemsNo);
	}

	public boolean add(Boarditems boarditems) {


		if(boardItemsDao.add(boarditems) > 0){
			return true;
		}
		else{

			return false;
		}
	}

	public boolean modify(Boarditems boarditems) {

		if(boardItemsDao.modify(boarditems) > 0){
			return true;
		}
		else{

			return false;
		}
	}

	public boolean remove(long boardItemsNo) {

		if(boardItemsDao.remove(boardItemsNo) > 0){
			return true;
		}
		else{

			return false;
		}
	}

	public Boarditems count(long boardItemsNo) {

		int result = boardItemsDao.itemscounts(boardItemsNo);

		Boarditems boardItem = null;

		if(result > 0){

			boardItem = boardItemsDao.view(boardItemsNo);	
		}
		return boardItem;
	}

	public int countBoardItem(long boardListNo, String searchCondition,
			String searchTitle) {
		int totalCount = 0;

		if (searchTitle == null || searchTitle.trim().length() == 0) {

			totalCount = boardItemsDao.countBoardItemNotNotice(boardListNo);
		}
		else {

			if (searchCondition.equals("T")) {
				totalCount = 
						boardItemsDao.countBoardItemNotNoticeByTitle(
								boardListNo, searchTitle);
			}
			else if (searchCondition.equals("C")) {
				totalCount = 
						boardItemsDao.countBoardItemNotNoticeByContent(
								boardListNo, searchTitle);
			}
			else if (searchCondition.equals("N")) {
				totalCount = 
						boardItemsDao.countBoardItemNotNoticeByMemberName(
								boardListNo, searchTitle);
			}
		}

		return totalCount;
	}

}
